package com.chenfan.magic.base;


import com.chenfan.magic.entity.Status;
import com.chenfan.magic.exception.IDCException;
import com.chenfan.magic.service.impl.StatusComponent;
import com.chenfan.magic.utils.SpringUtil;
import com.chenfan.magic.utils.StringKit;

/**
 * 状态索引枚举
 *
 * @author 周夕
 * @date 2020-02-15 18:14
 */
public class S {

    private static StatusComponent statusComponent;

    static {
        statusComponent = SpringUtil.getBean(StatusComponent.class);
    }

    public static Status get(String statusIndex) {
        Status status = statusComponent.get(statusIndex);
        return status;
    }

    public static R fail(Status status, String extendStr) {
        return R.fail(status.getStatusCode(), status.getStatusMsg() + (StringKit.isNotWhite(extendStr) ? extendStr : ""));
    }

    public static R fail(String statusIndex, String extendStr) {
        return fail(get(statusIndex), extendStr);
    }

    public static R fail(String statusIndex) {
        return fail(statusIndex, "");
    }

    public static R fail(Status status) {
        return fail(status, "");
    }

    public static boolean assets(Boolean trueOrFalse, String statusIndex) {
        if (!trueOrFalse) {
            throw new IDCException(S.fail(statusIndex));
        }
        return trueOrFalse;
    }

    public static boolean assetsX(Boolean trueOrFalse, String message) {
        if (!trueOrFalse) {
            throw new IDCException(message);
        }
        return trueOrFalse;
    }

    public static boolean assets(Boolean trueOrFalse) {
        return assets(trueOrFalse, S.COMMON_ASSETS);
    }


    ///////////////////////  状态码键表   ///////////////////////

    public static final String COMMON_ASSETS = "COMMON_ASSETS";
    public static final String NOT_NULL_PHONE = "NOT_NULL_PHONE";
    public static final String PHONE_ERROR = "PHONE_ERROR";
    public static final String NOT_NULL_EMAIL = "NOT_NULL_EMAIL";
    public static final String EMAIL_ERROR = "EMAIL_ERROR";
    public static final String PARAM_ERROR = "PARAM_ERROR";
    public static final String ACTIVE_VERIFY_NOT_ALLOW = "ACTIVE_VERIFY_NOT_ALLOW";
    public static final String CLIENT_INVALID = "CLIENT_INVALID";
    public static final String OPENID_GET_ERROR = "OPENID_GET_ERROR";

    public static final String GRANT_INVALID = "GRANT_INVALID";
    public static final String GRANT_INVALID_NOT_EQUALS_OPENID = "GRANT_INVALID_NOT_EQUALS_OPENID";
    public static final String GRANT_INVALID_NOT_FIND_USER = "GRANT_INVALID_NOT_FIND_USER";
    public static final String GRANT_INVALID_NOT_FIND_ISV_USER = "GRANT_INVALID_NOT_FIND_ISV_USER";

    public static final String NOT_EXIST_APP_KEY = "NOT_EXIST_APP_KEY";
    public static final String NOT_EXIST_ISV = "NOT_EXIST_ISV";
    public static final String ISV_OFFLINE = "ISV_OFFLINE";
    public static final String ISV_GRAY_NOT_ALLOW = "ISV_GRAY_NOT_ALLOW";
    public static final String ISV_DEV = "ISV_DEV";
    public static final String ISV_EXC = "ISV_EXC";
    public static final String ISV_IN_CHECK = "ISV_IN_CHECK";
    public static final String ISV_CHECK_FALSE = "ISV_CHECK_FALSE";
    public static final String ISV_FORBIDDEN = "ISV_FORBIDDEN";

    public static final String SESSION_INVALID = "SESSION_INVALID";
    public static final String PASSPORT_CHECK_ERROR = "PASSPORT_CHECK_ERROR";
    public static final String PASSPORT_NOT_EQUALS = "PASSPORT_NOT_EQUALS";

    public static final String MUST_AGREE_PROCOTOL = "MUST_AGREE_PROCOTOL";
    public static final String ERROR_VERIFY_CODE = "ERROR_VERIFY_CODE";
    public static final String NOT_NULL_USERNAME = "NOT_NULL_USERNAME";
    public static final String NOT_NULL_PASSWORD = "NOT_NULL_PASSWORD";
    public static final String ERROR_LENGTH_USERNAME = "ERROR_LENGTH_USERNAME";
    public static final String ERROR_LENGTH_PASSWORD = "ERROR_LENGTH_PASSWORD";
    public static final String USERNAME_USED = "USERNAME_USED";
    public static final String PHONE_USED = "PHONE_USED";
    public static final String EMAIL_USED = "EMAIL_USED";

    public static final String PASSWORD_NOT_COPY = "PASSWORD_NOT_COPY";
    public static final String PHONE_NOT_REG = "PHONE_NOT_REG";
    public static final String EMAIL_NOT_REG = "EMAIL_NOT_REG";

    public static final String ROBOT_VERIFY_EXPIRE = "ROBOT_VERIFY_EXPIRE";
    public static final String ROBOT_VERIFY_ERROR = "ROBOT_VERIFY_ERROR";

    public static final String NOT_NULL_LOGINNAME = "NOT_NULL_LOGINNAME";
    public static final String USERNAME_NOT_REG = "USERNAME_NOT_REG";
    public static final String USER_FORBID = "USER_FORBID";
    public static final String USER_STATUS_EXC = "USER_STATUS_EXC";
    public static final String USER_CANCELED = "USER_CANCELED";
    public static final String USER_HAS_NOT_PASSWORD = "USER_HAS_NOT_PASSWORD";
    public static final String PASSWORD_ERROR = "PASSWORD_ERROR";
    public static final String NOT_NULL_CODE_PHONE = "NOT_NULL_CODE_PHONE";
    public static final String SESSION_EXPIRE = "SESSION_EXPIRE";
    public static final String ERROR_CODE_PHONE = "ERROR_CODE_PHONE";
    public static final String NOT_EXIST_USER = "NOT_EXIST_USER";
    public static final String GRANT_ERROR = "GRANT_ERROR";

    public static final String SCENE_CODE_INVALID = "SCENE_CODE_INVALID";

    public static final String SWITCH_CLOSE_REG = "SWITCH_CLOSE_REG";
    public static final String SWITCH_CLOSE_LOGIN_BY_PHONE = "SWITCH_CLOSE_LOGIN_BY_PHONE";
    public static final String SWITCH_CLOSE_REG_BY_PHONE = "SWITCH_CLOSE_REG_BY_PHONE";
    public static final String SWITCH_CLOSE_FIND_BY_PHONE = "SWITCH_CLOSE_FIND_BY_PHONE";
    public static final String SWITCH_CLOSE_FIND_BY_EMAIL = "SWITCH_CLOSE_FIND_BY_EMAIL";
    public static final String SWITCH_CLOSE_REG_BY_EMAIL = "SWITCH_CLOSE_REG_BY_EMAIL";
    public static final String SWITCH_CLOSE_LOGIN_BY_ACCOUNT = "SWITCH_CLOSE_LOGIN_BY_ACCOUNT";

    public static final String PROCOTOL_ENCRYPT_ERROR = "PROCOTOL_ENCRYPT_ERROR";
    public static final String PROCOTOL_DECRYPT_ERROR = "PROCOTOL_DECRYPT_ERROR";

    public static final String MQL_CAN_NOT_FOUND = "MQL_CAN_NOT_FOUND";
    public static final String MQL_NOT_EXIST = "MQL_NOT_EXIST";
    public static final String MQL_CONTEXT_NULL = "MQL_CONTEXT_NULL";
    public static final String MQL_INVAILD_REST = "MQL_INVAILD_REST";
    public static final String MQL_NOT_MATCH_REST = "MQL_NOT_MATCH_REST";
    public static final String MQL_GRAY_OPEN = "MQL_GRAY_OPEN";
    public static final String MQL_VALIDATE_UNKNOW_TOKEN_ARROW_FOR_EMPTY_BUCKET = "MQL_VALIDATE_UNKNOW_TOKEN_ARROW_FOR_EMPTY_BUCKET";
    public static final String MQL_VALIDATE_UNKNOW_TOKEN_ARROW = "MQL_VALIDATE_UNKNOW_TOKEN_ARROW";
    public static final String MQL_INVAILD_REQUEST_PARAMS = "MQL_INVAILD_REQUEST_PARAMS";
    public static final String MQL_INVAILD_REQUEST_PARAM = "MQL_INVAILD_REQUEST_PARAM";

    public static final String IDC_ENVIR_CODE_NULL = "IDC_ENVIR_CODE_NULL";
    public static final String IDC_ENVIR_CODE_INVAILD = "IDC_ENVIR_CODE_INVAILD";
    public static final String IDC_DATASOURCE_GROUP_EMPTY = "IDC_DATASOURCE_GROUP_EMPTY";
    public static final String IDC_DATASOURCE_NULL = "IDC_DATASOURCE_NULL";
    public static final String IDC_DATASOURCE_FORBIDDEN = "IDC_DATASOURCE_FORBIDDEN";
    public static final String IDC_RESOLVER_SCRIPT_LANGUAGE_REQUIRED = "IDC_RESOLVER_SCRIPT_LANGUAGE_REQUIRED";
    public static final String IDC_RESOLVER_HTTP_URL_REQUIRED = "IDC_RESOLVER_HTTP_URL_REQUIRED";
    public static final String IDC_RESOLVER_REDIS_KEY_REQUIRED = "IDC_RESOLVER_REDIS_KEY_REQUIRED";
    public static final String IDC_RESOLVER_UNKNOW_TAG = "IDC_RESOLVER_UNKNOW_TAG";

    public static final String IDC_DATASOURCE_TYPE_CODE_NULL = "IDC_DATASOURCE_TYPE_CODE_NULL";
    public static final String IDC_DATASOURCE_TYPE_UNSUPPORT = "IDC_DATASOURCE_TYPE_UNSUPPORT";
    public static final String IDC_DATASOURCE_TYPE_FORBIDDEN = "IDC_DATASOURCE_TYPE_FORBIDDEN";
    public static final String IDC_DATASOURCE_TYPE_SUPPORT_STOP = "IDC_DATASOURCE_TYPE_SUPPORT_STOP";

    public static final String IDC_APP_LINE_INVAILD = "IDC_APP_LINE_INVAILD";


}
